package com.css.fxfzcpxx.modules.systemOperation.controller;

import com.css.fxfzcpxx.base.response.RestResponse;
import com.css.fxfzcpxx.modules.categoryView.param.QueParam;
import com.css.fxfzcpxx.modules.categoryView.service.CategoryViewService;
import com.css.fxfzcpxx.modules.systemOperation.service.SysOperationService;
import com.css.fxfzcpxx.modules.systemOperation.service.impl.SysOperationServiceImpl;
import com.css.fxfzcpxx.modules.systemOperation.vo.StatisticsDataVo;
import com.css.fxfzcpxx.util.PlatformPageUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/sysOperation")
@Slf4j
public class SysOperationController {
    @Autowired
    private SysOperationService sysOperationService;

    /***
     * 获取访问量、浏览量、检索量、下载量总量
     * @param
     * @return
     */
    @GetMapping("/getRecordTotal")
    public RestResponse getTotal(){
        RestResponse restResponse=null;
        try {
            Map<String,Object> map=sysOperationService.getRecordTotal();
            restResponse= RestResponse.succeed(map);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /***
     * 获取访问量统计数据
     * @param
     * @return
     */
    @GetMapping("/getVisitsStatisticsData")
    public RestResponse getVisitsStatisticsData(String unit){
        RestResponse restResponse=null;
        try {
            List<StatisticsDataVo>  map=sysOperationService.getVisitsStatisticsData(unit);
            restResponse= RestResponse.succeed(map);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /***
     * 获取浏览量统计数据
     * @param
     * @return
     */
    @GetMapping("/getPageViewStatisticsData")
    public RestResponse getPageViewStatisticsData(String unit){
        RestResponse restResponse=null;
        try {
            List<StatisticsDataVo> map=sysOperationService.getPageViewStatisticsData(unit);
            restResponse= RestResponse.succeed(map);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /***
     * 获取检索量统计数据
     * @param
     * @return
     */
    @GetMapping("/getRetrievalVolumeStatisticsData")
    public RestResponse getRetrievalVolumeStatisticsData(String unit){
        RestResponse restResponse=null;
        try {
            List<Map<String,Object>> map=sysOperationService.getRetrievalVolumeStatisticsData(unit);
            restResponse= RestResponse.succeed(map);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /***
     * 获取下载量统计数据
     * @param
     * @return
     */
    @GetMapping("/getDownloadStatisticsData")
    public RestResponse getDownloadStatisticsData(String unit){
        RestResponse restResponse=null;
        try {
            List<Map<String,Object>> map=sysOperationService.getDownloadStatisticsData(unit);
            restResponse= RestResponse.succeed(map);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /***
     * 获取浏览量统计排名
     * @param
     * @return
     */
    @GetMapping("/getPageViewRankingData")
    public RestResponse getPageViewRankingData(String unit){
        RestResponse restResponse=null;
        try {
            List<StatisticsDataVo> map=sysOperationService.getPageViewRankingData(unit);
            restResponse= RestResponse.succeed(map);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }

    /***
     * 获取浏览量统计排名(分页)
     * @param
     * @return
     */
    @GetMapping("/getPageViewRankingPage")
    public RestResponse getPageViewRankingPage(String unit, HttpServletRequest request){
        RestResponse restResponse=null;
        try {
            int curPage = Integer.valueOf(request.getParameter(PlatformPageUtils.CUR_PAGE));
            int pageSize=Integer.valueOf(request.getParameter(PlatformPageUtils.PAGE_SIZE));
            Map<String,Object> page=sysOperationService.getPageViewRankingPage(unit,curPage,pageSize);
            restResponse = RestResponse.succeed(page);
        }catch (Exception e){
            String errormessage="查询失败";
            log.error(errormessage,e);
            restResponse=RestResponse.fail(errormessage);
        }
        return restResponse;
    }






}
